package com.lpf.back.common;

import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import com.aliyun.oss.model.PutObjectRequest;

import java.io.ByteArrayInputStream;

public class OssImgUpload {

    public int uploadImg(byte[] bytes){
        // 创建OSSClient实例。
        OSS ossClient = new OSSClientBuilder().build(OssConstant.END_POINT, OssConstant.ACCESS_KEY_ID, OssConstant.ACCESS_KEY_SECRET);
        // 创建PutObjectRequest对象。
        // 填写Bucket名称和Object完整路径。Object完整路径中不能包含Bucket名称。
        PutObjectRequest putObjectRequest = new PutObjectRequest(OssConstant.BUCKET, "exampleobject.txt", new ByteArrayInputStream(bytes));
        //上传文件
        ossClient.putObject(putObjectRequest);
        ossClient.shutdown();
        return 1;
    }

}
